//
//  HJOderDetailController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/30.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJOderDetailController.h"
#import "HJPayViewController.h"
#import "HJGoodsAdressController.h"
#import "HJLogisticsViewController.h" // 物流信息

#import "HJOrderDetailModel.h"

@interface HJOderDetailController ()
@property (weak, nonatomic) IBOutlet UIImageView *shipImage;
@property (weak, nonatomic) IBOutlet UILabel *shipTitle;
@property (weak, nonatomic) IBOutlet UILabel *shipMoney;
@property (weak, nonatomic) IBOutlet UILabel *shipStatue;
@property (weak, nonatomic) IBOutlet UILabel *shipNoAndTime;

@property (weak, nonatomic) IBOutlet UILabel *shoeCode;
@property (weak, nonatomic) IBOutlet UILabel *shoeMoney;

@property (weak, nonatomic) IBOutlet UILabel *buyTime;
@property (weak, nonatomic) IBOutlet UILabel *remainTime;

@property (weak, nonatomic) IBOutlet UILabel *goodsName;
@property (weak, nonatomic) IBOutlet UILabel *address;
@property (weak, nonatomic) IBOutlet UILabel *phoneNo;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *instructionH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *instructionSuperH;
@property (weak, nonatomic) IBOutlet UILabel *instruction;

@property (weak, nonatomic) IBOutlet UIView *logisticsView;
@property (weak, nonatomic) IBOutlet UIButton *logisticsBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *logisticsh;
@property (weak, nonatomic) IBOutlet UILabel *logistics;
@property (weak, nonatomic) IBOutlet UILabel *logisticsTime;

@property (weak, nonatomic) IBOutlet UIView *back;


@property(nonatomic,strong)HJOrderDetailModel * model;
@end

@implementation HJOderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.buyTime.font =HJFontSize(mScreenWidth/414 * 15);
    self.remainTime.font =HJFontSize(mScreenWidth/414 * 15);
    self.goodsName.font =HJFontSize(mScreenWidth/414 * 15);
    self.address.font =HJFontSize(mScreenWidth/414 * 15);
    self.phoneNo.font =HJFontSize(mScreenWidth/414 * 15);
    self.logisticsTime.font =HJFontSize(mScreenWidth/414 * 15);
    self.logistics.font =HJFontSize(mScreenWidth/414 * 15);
    self.instruction.font =HJFontSize(mScreenWidth/414 * 15);
    
    [self loadWork];
}

-(void)loadWork {
    NSMutableDictionary* params =[NSMutableDictionary dictionary];
    params[@"type"] = self.type;
    params[@"want_buy_id"] = self.want_buy_id;
    params[@"order_id"] = self.order_id;
    [TZHttpTool post:OderDetailAPI params:params success:^(NSDictionary *result) {
        self.model =[[HJOrderDetailModel alloc]init];
        self.model = [HJOrderDetailModel mj_objectWithKeyValues:result[@"data"]];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.back removeFromSuperview];
            [self.shipImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",self.model.shoes.avatar_base_url,self.model.shoes.avatar_path]]];
            self.shipTitle.text = self.model.shoes.shoes_name;
            self.shipMoney.text =[NSString stringWithFormat:@"￥%@", self.model.shoes.sell_money];
            self.shipNoAndTime.text = [NSString stringWithFormat:@"%@  %@",self.model.shoes.shoes_article_number,[CommonTools getTimeStrBytimeStamp:self.model.shoes.sell_date]];
            self.shoeCode.text = [NSString stringWithFormat:@"%@码",self.model.shoes_size];
            self.shoeMoney.text =[NSString stringWithFormat:@"￥%@", self.model.pay_reality];
            self.buyTime.text = self.model.shoes_date;
            self.remainTime.text = self.model.day;
            self.logisticsTime.text = self.model.express.time;
            self.logistics.text = self.model.express.status;
            self.goodsName.text = [NSString stringWithFormat:@"收货人：%@",self.model.addresser];
            self.address.text = [NSString stringWithFormat:@"地  址：%@",self.model.addresser_detail];
            self.phoneNo.text= [NSString stringWithFormat:@"手机号：%@",self.model.addresser_mobile];
        });
    } failure:^(NSString *msg) {
        [self showErrorHUDWithError:msg];
    }];
}

// 物流信息
- (IBAction)logisticsBtn:(UIButton *)sender {
    
    if ([self.model.express.express isEqualToString:@""]) {
        [self showSuccessHUDWithStr:@"暂未发货"];
        return;
    }
    HJLogisticsViewController * logisticsVC = [[HJLogisticsViewController alloc]init];
    logisticsVC.shoes_name = self.model.shoes.shoes_name;
    logisticsVC.shoes_size = self.model.shoes_size;
    logisticsVC.shoes_money = self.model.shoes.sell_money;
    logisticsVC.shoes_image = [NSString stringWithFormat:@"%@%@",self.model.shoes.avatar_base_url,self.model.shoes.avatar_path];
    logisticsVC.express = self.model.express.express;
    [self.navigationController pushViewController:logisticsVC animated:YES];
    
}

- (IBAction)pushShipAdress:(UIButton *)sender {
    HJGoodsAdressController * shippingVC = [[HJGoodsAdressController alloc]init];
    shippingVC.navTitle = @"地址选择";
    shippingVC.enditBool = NO;
    MJWeakSelf
    shippingVC.Blok = ^(NSString *name, NSString *address, NSString *mobile, NSString * adress_id) {
        weakSelf.goodsName.text = [NSString stringWithFormat:@"收货人：%@",name];
        weakSelf.address.text = [NSString stringWithFormat:@"地  址：%@",address];
        weakSelf.phoneNo.text= [NSString stringWithFormat:@"手机号：%@",mobile];
    };
    [self.navigationController pushViewController:shippingVC animated:YES];
}

- (IBAction)bottomPayBtn:(UIButton *)sender {
    HJPayViewController * payVC = [[HJPayViewController alloc]init];
    payVC.navTitle = @"支付中心";
    [self.navigationController pushViewController:payVC animated:YES];
}

@end
